---
title: "Online Appendix"
subtitle: "Power-Sharing & Exclusion: Toward a Theory of Herrenvolk Democracy"
author: "Jessala A. Grijalva"
date: "`r format(Sys.Date(), '%B %d, %Y')`"
format:
  pdf:
    toc: true
    toc-depth: 2
    number-sections: false
    geometry: margin=1in
    colorlinks: true
    keep-tex: false
execute:
  warning: false
  message: false
  echo: false
---

```{r}
#| label: setup

source(here::here("R", "00_setup.R"))

# ── Load precomputed results ────────────────────────────────────────────────
# Render Phase 1 and Phase 2 first to generate these files
load(here("data", "processed", "psi_phase1_results.rda"))
load(here("data", "processed", "psi_phase2_results.rda"))

usa_psi       <- psi_phase1$usa_psi
alpha_result  <- psi_phase2$alpha_result
cor_matrix    <- psi_phase2$cor_matrix
pca_result    <- psi_phase2$pca_result
var_explained <- psi_phase2$var_explained
kmo_result    <- psi_phase2$kmo_result
decade_summary <- psi_phase2$decade_summary
```

\newpage

# A: PSI Component Specification

```{r}
#| label: tbl-a-components

tibble(
  Component   = unname(PSI_LABELS),
  Variable    = names(PSI_LABELS),
  Description = c(
    "Political power distributed across racial, ethnic, religious groups",
    "Political power distributed between men and women",
    "Equal civil liberties across social groups",
    "Freedom from government torture",
    "Freedom from political killings"
  ),
  `First Year` = 1789
) |>
  gt() |>
  tab_header(title = "Table A1: Final PSI Components") |>
  tab_options(table.width = pct(100))
```

\noindent \textit{Note.} All five components have complete temporal coverage from 1789. Variables selected from V-Dem v15 based on temporal coverage, conceptual fit (low scores during known exclusion), and non-redundancy.

\newpage

# B: Aggregation Method Comparison

```{r}
#| label: fig-b-methods
#| fig-cap: "Figure B1: PSI by Aggregation Method"
#| fig-height: 6

usa_psi |>
  select(year, psi_additive, psi_multiplicative, psi_hybrid) |>
  pivot_longer(-year, names_to = "Method", values_to = "PSI") |>
  mutate(Method = case_when(
    Method == "psi_additive" ~ "Additive",
    Method == "psi_multiplicative" ~ "Multiplicative",
    Method == "psi_hybrid" ~ "Hybrid"
  ) |> factor(levels = c("Additive", "Multiplicative", "Hybrid"))) |>
  ggplot(aes(x = year, y = PSI, color = Method)) +
  geom_line(linewidth = 1) +
  geom_vline(xintercept = c(1865, 1920, 1965), linetype = "dashed", alpha = 0.4) +
  scale_color_manual(values = c("Additive" = "black",
                                "Multiplicative" = ELEC_COLOR,
                                "Hybrid" = PSI_COLOR)) +
  scale_y_continuous(limits = c(0, 1), labels = percent) +
  labs(title = "PSI by Aggregation Method",
       subtitle = "All methods produce the same substantive pattern",
       x = NULL, y = "Power-Sharing Index") +
  theme_psi()
```

\noindent \textit{Note.} Vertical dashed lines mark the end of the Civil War (1865), women's suffrage (1920), and the Voting Rights Act (1965). All three methods produce the same substantive periodization; they differ only in magnitude. See Phase 1 for full aggregation sensitivity analysis.

\newpage

# C: Internal Consistency

```{r}
#| label: fig-c-correlations
#| fig-cap: "Figure C1: Inter-Item Correlation Matrix"
#| fig-height: 5

ggcorrplot(cor_matrix, type = "lower", lab = TRUE, lab_size = 4,
           colors = c("#6D9EC1", "white", "#E46726"),
           title = "Inter-Item Correlations")
```

\noindent \textit{Note.} All inter-item correlations exceed 0.60. Cronbach's $\alpha$ = `r round(alpha_result$total$raw_alpha, 2)` (excellent internal consistency).

```{r}
#| label: tbl-c-alpha

alpha_result$alpha.drop |>
  as.data.frame() |>
  rownames_to_column("Component") |>
  mutate(Component = case_when(
    str_detect(Component, "pepwrsoc") ~ "Social Group Power",
    str_detect(Component, "pepwrgen") ~ "Gender Power",
    str_detect(Component, "clsocgrp") ~ "Civil Liberties Equality",
    str_detect(Component, "cltort") ~ "Freedom from Torture",
    str_detect(Component, "clkill") ~ "Freedom from Killings"
  )) |>
  select(Component, raw_alpha, std.alpha) |>
  gt() |>
  tab_header(title = "Table C1: Alpha if Item Dropped") |>
  fmt_number(columns = c(raw_alpha, std.alpha), decimals = 3)
```

\noindent \textit{Note.} No component substantially increases $\alpha$ when dropped, confirming that all five belong in the index.

\newpage

# D: Dimensionality

```{r}
#| label: tbl-d-pca

tibble(
  PC = 1:5,
  `Variance Explained (%)` = var_explained,
  `Cumulative (%)` = cumsum(var_explained)
) |>
  gt() |>
  tab_header(title = "Table D1: PCA Variance Explained") |>
  fmt_number(columns = c(`Variance Explained (%)`, `Cumulative (%)`), decimals = 1)
```

\noindent \textit{Note.} PC1 explains `r round(var_explained[1], 1)`\% of variance, confirming unidimensionality. KMO = `r round(kmo_result$MSA, 2)` ("meritorious").

\newpage

# E: Convergent & Discriminant Validity

```{r}
#| label: tbl-e-era-corr

usa_psi |>
  group_by(era) |>
  summarise(
    N = n(),
    `r(PSI, Electoral)` = safe_cor(psi_additive, v2x_polyarchy),
    `r(PSI, Liberal)` = safe_cor(psi_additive, v2x_libdem),
    `r(PSI, Participatory)` = safe_cor(psi_additive, v2x_partipdem),
    .groups = "drop"
  ) |>
  gt() |>
  tab_header(title = "Table E1: Era-Specific Correlations") |>
  fmt_number(columns = -c(era, N), decimals = 3)
```

\noindent \textit{Note.} During the Herrenvolk era (1789--1865), PSI shows a negative correlation with Electoral Democracy, confirming discriminant validity. Egalitarian and Deliberative indices excluded (begin 1900).

\newpage

# F: Uncertainty Quantification

```{r}
#| label: fig-f-ci
#| fig-cap: "Figure F1: PSI with 95% Confidence Intervals"
#| fig-height: 5

ggplot() +
  geom_ribbon(data = decade_summary, aes(x = year_mid, ymin = ci_lo, ymax = ci_hi),
              fill = ELEC_COLOR, alpha = 0.3) +
  geom_line(data = usa_psi, aes(x = year, y = psi_additive), linewidth = 0.8) +
  geom_point(data = decade_summary, aes(x = year_mid, y = mean), color = "darkblue", size = 2) +
  scale_y_continuous(limits = c(0, 1), labels = percent) +
  labs(title = "PSI with 95% Confidence Intervals",
       subtitle = "Within-decade variation",
       x = NULL, y = "Power-Sharing Index") +
  theme_psi()
```

\noindent \textit{Note.} Blue ribbon shows 95\% CIs from within-decade variation. Confidence intervals do not overlap across eras.

\newpage

# G: Jackknife Sensitivity

```{r}
#| label: fig-g-jackknife
#| fig-cap: "Figure G1: Jackknife Sensitivity Analysis"
#| fig-height: 6

usa_psi |>
  mutate(
    Full = psi_additive,
    `Drop: Social Group` = (v2pepwrgen_norm + v2clsocgrp_norm + v2cltort_norm + v2clkill_norm) / 4,
    `Drop: Gender` = (v2pepwrsoc_norm + v2clsocgrp_norm + v2cltort_norm + v2clkill_norm) / 4,
    `Drop: Civil Liberties` = (v2pepwrsoc_norm + v2pepwrgen_norm + v2cltort_norm + v2clkill_norm) / 4,
    `Drop: Torture` = (v2pepwrsoc_norm + v2pepwrgen_norm + v2clsocgrp_norm + v2clkill_norm) / 4,
    `Drop: Killings` = (v2pepwrsoc_norm + v2pepwrgen_norm + v2clsocgrp_norm + v2cltort_norm) / 4
  ) |>
  select(year, Full, starts_with("Drop")) |>
  pivot_longer(-year, names_to = "Version", values_to = "PSI") |>
  mutate(Version = factor(Version, levels = c("Full", "Drop: Social Group", "Drop: Gender",
                                               "Drop: Civil Liberties", "Drop: Torture", "Drop: Killings"))) |>
  ggplot(aes(x = year, y = PSI, color = Version, linewidth = Version)) +
  geom_line() +
  scale_color_manual(values = c("Full" = "black", "Drop: Social Group" = "#1b9e77", "Drop: Gender" = "#d95f02",
                                "Drop: Civil Liberties" = "#7570b3", "Drop: Torture" = "#e7298a", "Drop: Killings" = "#66a61e")) +
  scale_linewidth_manual(values = c(1.5, rep(0.6, 5))) +
  scale_y_continuous(limits = c(0, 1), labels = percent) +
  labs(title = "Jackknife Sensitivity Analysis",
       subtitle = "No single component drives substantive conclusions",
       x = NULL, y = "PSI (Additive)") +
  theme_psi() +
  guides(linewidth = "none")
```

\noindent \textit{Note.} Black line = full 5-component index. Colored lines = index with each component dropped. No single component changes the substantive pattern.

\newpage

# H: Software and Session Information

```{r}
#| label: session

sessionInfo()
```
